﻿using Ping9719.WpfEx;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;
using HandyControl.Controls;
using System.Reflection;
using BaseUi.ViewModels;
using System.ComponentModel;
using BaseUi.Views.MainWindows;
using System.Threading;

namespace BaseUi.Views.PlcView
{
    public class MachbujinData : INotifyPropertyChanged
    {
        public CommonViewModel CommonViewModel { get; set; }
        private string conditiony = "";
        private string conditionz = "";
        private string conditionu1 = "";
        private string conditionu2 = "";
        private string conditionu3 = "";
        public string ditionz
        {
            get { return conditionz; }
            set
            {
                conditionz = value;

                OnPropertyChanged("ditionz");
            }
        }
        public string ditiony
        {
            get { return conditiony; }
            set
            {
                conditiony = value;

                OnPropertyChanged("ditiony");
            }
        }
        public string ditionu1
        {
            get { return conditionu1; }
            set
            {
                conditionu1 = value;

                OnPropertyChanged("ditionu1");
            }
        }
        public string ditionu2
        {
            get { return conditionu2; }
            set
            {
                conditionu2 = value;

                OnPropertyChanged("ditionu2");
            }
        }
        public string ditionu3
        {
            get { return conditionu3; }
            set
            {
                conditionu3 = value;

                OnPropertyChanged("ditionu3");
            }
        }


        private string cwuchay = "";
        private string cwuchaz = "";
        private string cwuchau1 = "";
        private string cwuchau2 = "";
        private string cwuchau3 = "";
        public string wuchay
        {
            get { return cwuchay; }
            set
            {
                cwuchay = value;

                OnPropertyChanged("wuchay");
            }
        }
        public string wuchaz
        {
            get { return cwuchaz; }
            set
            {
                cwuchaz = value;

                OnPropertyChanged("wuchaz");
            }
        }
        public string wuchau1
        {
            get { return cwuchau1; }
            set
            {
                cwuchau1 = value;

                OnPropertyChanged("wuchau1");
            }
        }
        public string wuchau2
        {
            get { return cwuchau2; }
            set
            {
                cwuchau2 = value;

                OnPropertyChanged("wuchau2");
            }
        }
        public string wuchau3
        {
            get { return cwuchau3; }
            set
            {
                cwuchau3 = value;

                OnPropertyChanged("wuchau3");
            }
        }
        private string cweizhiy = "";
        private string cweizhiz = "";
        private string cweizhiu1 = "";
        private string cweizhiu2 = "";
        private string cweizhiu3 = "";
        private string csudy = "";
        private string csudz = "";
        private string csudu1 = "";
        private string csudu2 = "";
        private string csudu3 = "";

        public string weizhiy
        {
            get { return cweizhiy; }
            set
            {
                cweizhiy = value;

                OnPropertyChanged("weizhiy");
            }
        }
        public string weizhiz
        {
            get { return cweizhiz; }
            set
            {
                cweizhiz = value;

                OnPropertyChanged("weizhiz");
            }
        }
        public string weizhiu1
        {
            get { return cweizhiu1; }
            set
            {
                cweizhiu1 = value;

                OnPropertyChanged("weizhiu1");
            }
        }
        public string weizhiu2
        {
            get { return cweizhiu2; }
            set
            {
                cweizhiu2 = value;

                OnPropertyChanged("weizhiu2");
            }
        }
        public string weizhiu3
        {
            get { return cweizhiu3; }
            set
            {
                cweizhiu3 = value;

                OnPropertyChanged("weizhiu3");
            }
        }
        public string sudy
        {
            get { return csudy; }
            set
            {
                csudy = value;

                OnPropertyChanged("sudy");
            }
        }
        public string sudz
        {
            get { return csudz; }
            set
            {
                csudz = value;

                OnPropertyChanged("sudz");
            }
        }
        public string sudu1
        {
            get { return csudu1; }
            set
            {
                csudu1 = value;

                OnPropertyChanged("sudu1");
            }
        }
        public string sudu2
        {
            get { return csudu2; }
            set
            {
                csudu2 = value;

                OnPropertyChanged("sudu2");
            }
        }
        public string sudu3
        {
            get { return csudu3; }
            set
            {
                csudu3 = value;

                OnPropertyChanged("sudu3");
            }
        }

        private string cweizhitu = "";
        private string csudru = "";
        private string csudcu = "";
        private string csudtu = "";
        private string csudsu = "";
        public string weizhitu
        {
            get { return cweizhitu; }
            set
            {
                cweizhitu = value;

                OnPropertyChanged("weizhitu");
            }
        }
        public string sudru
        {
            get { return csudru; }
            set
            {
                csudru = value;

                OnPropertyChanged("sudru");
            }
        }
        public string sudcu
        {
            get { return csudcu; }
            set
            {
                csudcu = value;

                OnPropertyChanged("sudcu");
            }
        }
        public string sudtu
        {
            get { return csudtu; }
            set
            {
                csudtu = value;

                OnPropertyChanged("sudtu");
            }
        }
        public string sudsu
        {
            get { return csudsu; }
            set
            {
                csudsu = value;

                OnPropertyChanged("sudsu");
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
        /// <summary>
        /// MachineView.xaml 的交互逻辑
        /// </summary>
        public partial class MachineView : UserControlBase
    {
        private StudentData viewModel = new StudentData();
        private MachbujinData bujinModel = new MachbujinData();
        public SolidColorBrush BoroColor = new SolidColorBrush(Color.FromRgb(220, 220, 220));
        public SolidColorBrush GreenColor = new SolidColorBrush(Color.FromRgb(173, 255, 47));
        private bool bujin = false;
        public MachineView()
        {
            InitializeComponent();
            DataContext = bujinModel;
            bujinModel.CommonViewModel = MainWindow4.viewModel.CommonViewModel;
            viewModel.CommonViewModel = MainWindow4.viewModel.CommonViewModel;
        }

        private void loadFirst(object sender, EventArgs e)
        {
            if (this.IsInDesignMode)
                return;
            getyundong(); 
            getdinwei();
            getbujinjl();
            changclor(bujin);
            Task Machbujin = new Task(() =>
            {
                while (true)
                {
                    getnewzhuangtai();
                    getnewnow();
                    Thread.Sleep(200);
                }
            });
            Machbujin.Start();
        }
        /// <summary>
        /// 步进距离
        /// </summary>
        private void getbujinjl()
        {
            var io2 = LocalStatic.Plc.Read<float>("1454");
            if (io2.IsSucceed == false)
            {
                MacBox1g1z1.Text = "未接收";
            }
            else { MacBox1g1z1.Text = io2.Value.ToString(); }
            io2 = LocalStatic.Plc.Read<float>("1462");
            if (io2.IsSucceed == false)
            {
                MacBox1g1z2.Text = "未接收";
            }
            else { MacBox1g1z2.Text = io2.Value.ToString(); }
            io2 = LocalStatic.Plc.Read<float>("1458");
            if (io2.IsSucceed == false)
            {
                MacBox1g1z3.Text = "未接收";
            }
            else { MacBox1g1z3.Text = io2.Value.ToString(); }
        }
        /// <summary>
        /// 当前位置 当前速度
        /// </summary>
        private void getnewnow()
        {
            var ioi = LocalStatic.Plc.Read<float>("12");
            if (ioi.IsSucceed ==false)
            {
                bujinModel.weizhiy = "未接收";
            }
            else
            {
                bujinModel.weizhiy = ioi.Value.ToString();
            }

            ioi = LocalStatic.Plc.Read<float>("14");
            if (ioi.IsSucceed == false)
            {
                bujinModel.weizhiz = "未接收";
            }
            else
            {
                bujinModel.weizhiz = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<float>("16");
            if (ioi.IsSucceed == false)
            {
                bujinModel.weizhiu1 = "未接收";
            }
            else
            {
                bujinModel.weizhiu1 = ioi.Value.ToString();
            }
            //速度
            ioi = LocalStatic.Plc.Read<float>("48");
            if (ioi.IsSucceed == false)
            {
                bujinModel.sudy = "未接收";
            }
            else
            {
                bujinModel.sudy = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<float>("50");
            if (ioi.IsSucceed == false)
            {
                bujinModel.sudz = "未接收";
            }
            else
            {
                bujinModel.sudz = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<float>("52");
            if (ioi.IsSucceed == false)
            {
                bujinModel.sudu1 = "未接收";
            }
            else
            {
                bujinModel.sudu1 = ioi.Value.ToString();
            }
        }
        /// <summary>
        /// 轴状态
        /// </summary>
        private void getnewzhuangtai()
        {
            var retuly = LocalStatic.Plc.Read<Int16>("64");
            var retulz = LocalStatic.Plc.Read<Int16>("65");
            var retulu1 = LocalStatic.Plc.Read<Int16>("66");
            bujinModel.ditiony = getnumber(retuly.Value);
            bujinModel.ditionz = getnumber(retulz.Value);
            bujinModel.ditionu1 = getnumber(retulu1.Value);
        }

        private string getnumber(int ind)
        {
            string retul="未接受信息";
            if (ind==1) {
                retul = "未使能";
            }
            else if (ind == 2)
            {
                retul = "使能状态";
            }
            else if (ind == 3)
            {
                retul = "运动状态";
            }
            else if (ind == 4)
            {
                retul = "回原中";
            }
            else if (ind == 5)
            {
                retul = "轴故障";
            }
            return retul;
        }

        private void getveloc(int inder)
        {
            veloc1.Background = BoroColor;
            veloc2.Background = BoroColor;
            veloc3.Background = BoroColor;
            if (inder == 0)
            {

                veloc1.Background = GreenColor;
            }
            else if (inder == 1)
            {

                veloc2.Background = GreenColor;
            }
            else if (inder == 2)
            {

                veloc3.Background = GreenColor;
            }
        }
        private void changclor(bool bucolor)
        {
            if (bujin)
            {
                butjog.Background = BoroColor;
                butbujin.Background = GreenColor;
            }
            else
            {
                butjog.Background = GreenColor;
                butbujin.Background = BoroColor;
            }
        }
        /// <summary>
        /// 运动允许误差
        /// </summary>
        private void getyundong()
        {
            var io2 = LocalStatic.Plc.Read<float>("1800");
            if (io2.IsSucceed == false)
            {
                MacBox2g2z1.Text = "未接收";
            }
            else { MacBox2g2z1.Text = io2.Value.ToString(); }
            io2 = LocalStatic.Plc.Read<float>("1802");
            if (io2.IsSucceed == false)
            {
                MacBox2g2z2.Text = "未接收";
            }
            else { MacBox2g2z2.Text = io2.Value.ToString(); }
            io2 = LocalStatic.Plc.Read<float>("1804");
            if (io2.IsSucceed == false)
            {
                MacBox2g2z3.Text = "未接收";
            }
            else { MacBox2g2z3.Text = io2.Value.ToString(); }
        }
        /// <summary>
        /// jog按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void outblenButton_Click1g1z1(object sender, RoutedEventArgs e)
        {
            bujin = false;
            changclor(bujin);
        }
        /// <summary>
        /// 步进按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void outblenButton_Click1g1z2(object sender, RoutedEventArgs e)
        {
            bujin = true;
            changclor(bujin);
            getbujinjl();
        }
        /// <summary>
        /// 定位位置
        /// </summary>
        private void getdinwei()
        {
            var ioi = LocalStatic.Plc.Read<float>("1452");
            if (ioi.IsSucceed==false)
            {
                MacBox2g1z1.Text = "未接收";
            }
            else
            {
                MacBox2g1z1.Text = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<float>("1460");
            if (ioi.IsSucceed == false)
            {
                MacBox2g1z2.Text = "未接收";
            }
            else
            {
                MacBox2g1z2.Text = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<float>("1456");
            if (ioi.IsSucceed == false)
            {
                MacBox2g1z3.Text = "未接收";
            }
            else
            {
                MacBox2g1z3.Text = ioi.Value.ToString();
            }
        }
        private void outblenButton_Click2g1z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("33", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
            
        }

        private void outblenButton_Click2g1z2(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("34", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outblenButton_Click2g2z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("45", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outblenButton_Click2g2z2(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("46", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outblenButton_Click2g3z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("68", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outblenButton_Click2g3z2(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("69", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                
                Growl.Error(ee.ToString());
            }
        }

        private void outblenButton_Click3g2z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<Int16>("5", 0);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
                
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outblenButton_Click3g2z2(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<Int16>("5", 1);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
                
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outblenButton_Click3g2z3(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<Int16>("5", 2);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
                
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }
        /// <summary>
        /// Y轴到安全位
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void outblenButton_Click3g3z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("111", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }
        private void Checked(object sender, RoutedEventArgs e)
        {
            try
            {
                short ni = 1;
                if (machtogg.IsChecked == true)
                {
                    ni = 0;
                }
                else
                {
                    ni = 1;
                }
                var ioi = LocalStatic.Plc.Write<Int16>("1000", ni);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void yundongwucy(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(MacBox2g2z1.Text);
                var ioi = LocalStatic.Plc.Write<float>("1800", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {

                Growl.Error(ee.ToString());
            }
        }

        private void yundongwucz(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(MacBox2g2z2.Text);
                var ioi = LocalStatic.Plc.Write<float>("1802", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {

                Growl.Error(ee.ToString());
            }
        }

        private void yundongwucu(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(MacBox2g2z3.Text);
                var ioi = LocalStatic.Plc.Write<float>("1804", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {

                Growl.Error(ee.ToString());
            }
        }
        private void mach1g1z1p(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (!bujin)
                {

                    var ioi = LocalStatic.Plc.Write<bool>("66", false);
                    if (ioi.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }

                }
                else
                {

                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void mach1g1z1d(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (!bujin)
                {
                    var ioi = LocalStatic.Plc.Write<bool>("66", true);
                    if (ioi.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }
                }
                else
                {
                    float fait = float.Parse(MacBox1g1z3.Text);
                    if (fait<0)
                    {
                        fait = fait * (-1);
                    }
                    var ioi1 = LocalStatic.Plc.Write<float>("1458", fait);
                    if (ioi1.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }
                    var ioi = LocalStatic.Plc.Write<bool>("70", true);
                    if (ioi.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }
        private void mach1g2z1d(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (!bujin)
                {

                    var ioi = LocalStatic.Plc.Write<bool>("67", true);
                    if (ioi.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }

                }
                else
                {
                    float fait = float.Parse(MacBox1g1z3.Text);
                    if (fait > 0)
                    {
                        fait = fait * (-1);
                    }
                    var ioi1 = LocalStatic.Plc.Write<float>("1458", fait);
                    if (ioi1.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }
                    var ioi = LocalStatic.Plc.Write<bool>("70", true);
                    if (ioi.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void mach1g2z1p(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (!bujin)
                {

                    var ioi = LocalStatic.Plc.Write<bool>("67", false);
                    if (ioi.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }

                }
                else
                {

                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void mach2g2z1d(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (!bujin)
                {

                    var ioi = LocalStatic.Plc.Write<bool>("32", true);
                    if (ioi.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }

                }
                else
                {
                    float fait = float.Parse(MacBox1g1z1.Text);
                    if (fait > 0)
                    {
                        fait = fait * (-1);
                    }
                    var ioi1 = LocalStatic.Plc.Write<float>("1454", fait);
                    if (ioi1.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }
                    var ioi = LocalStatic.Plc.Write<bool>("35", true);
                    if (ioi.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void mach2g2z1p(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (!bujin)
                {

                    var ioi = LocalStatic.Plc.Write<bool>("32", false);
                    if (ioi.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }

                }
                else
                {

                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void mach2g1z1d(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (!bujin)
                {

                    var ioi = LocalStatic.Plc.Write<bool>("43", true);
                    if (ioi.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }

                }
                else
                {
                    float fait = float.Parse(MacBox1g1z2.Text);
                    if (fait<0)
                    {
                        fait = fait * (-1);
                    }
                    var ioi1 = LocalStatic.Plc.Write<float>("1462", fait);
                    if (ioi1.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }
                    var ioi = LocalStatic.Plc.Write<bool>("47", true);
                    if (ioi.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void mach2g1z1p(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (!bujin)
                {

                    var ioi = LocalStatic.Plc.Write<bool>("43", false);
                    if (ioi.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }

                }
                else
                {

                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void mach2g2z2d(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (!bujin)
                {

                    var ioi = LocalStatic.Plc.Write<bool>("31", true);
                    if (ioi.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }

                }
                else
                {
                    float fait = float.Parse(MacBox1g1z1.Text);
                    if (fait<0)
                    {
                        fait = fait * (-1);
                    }
                    var ioi1 = LocalStatic.Plc.Write<float>("1454", fait);
                    if (ioi1.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }
                    var ioi = LocalStatic.Plc.Write<bool>("35", true);
                    if (ioi.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void mach2g2z2p(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (!bujin)
                {

                    var ioi = LocalStatic.Plc.Write<bool>("31", false);
                    if (ioi.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }

                }
                else
                {

                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void mach2g3z1d(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (!bujin)
                {

                    var ioi = LocalStatic.Plc.Write<bool>("44", true);
                    if (ioi.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }

                }
                else
                {
                    float fait = float.Parse(MacBox1g1z2.Text);
                    if (fait > 0)
                    {
                        fait = fait * (-1);
                    }
                    var ioi1 = LocalStatic.Plc.Write<float>("1462", fait);
                    if (ioi1.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }
                    var ioi = LocalStatic.Plc.Write<bool>("47", true);
                    if (ioi.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void mach2g3z1p(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (!bujin)
                {

                    var ioi = LocalStatic.Plc.Write<bool>("44", false);
                    if (ioi.IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }

                }
                else
                {

                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void TextBox_KeyDowny(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                try
                {
                    float fait = float.Parse(MacBox2g1z1.Text);
                    if (LocalStatic.Plc.Write<float>("1452", fait).IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }
                }
                catch (Exception ee)
                {
                    Growl.Error(ee.ToString());
                }
            }
        }

        private void TextBox_KeyDownz(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                try
                {
                    float fait = float.Parse(MacBox2g1z2.Text);
                    if (LocalStatic.Plc.Write<float>("1460", fait).IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }
                }
                catch (Exception ee)
                {
                    Growl.Error(ee.ToString());
                }
            }
        }

        private void TextBox_KeyDownu1(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                try
                {
                    float fait = float.Parse(MacBox2g1z3.Text);
                    if (LocalStatic.Plc.Write<float>("1456", fait).IsSucceed == false)
                    {
                        Growl.Error("上传失败");
                    }
                }
                catch (Exception ee)
                {
                    Growl.Error(ee.ToString());
                }
            }
        }

        private void bujiny(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(MacBox1g1z1.Text);
                var ioi = LocalStatic.Plc.Write<float>("1454", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {

                Growl.Error(ee.ToString());
            }
        }

        private void bujinz(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(MacBox1g1z2.Text);
                var ioi = LocalStatic.Plc.Write<float>("1462", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {

                Growl.Error(ee.ToString());
            }
        }

        private void bujinu1(object sender, MouseButtonEventArgs e)
        {
            try
            {
                float fait = float.Parse(MacBox1g1z3.Text);
                var ioi = LocalStatic.Plc.Write<float>("1458", fait);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {

                Growl.Error(ee.ToString());
            }
        }
    }
}
